package com.example.demo.controller;

import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/redis")
public class RedisController {
    private final RedisTemplate redisTemplate;
    public RedisController(RedisTemplate redisTemplate)
    {
        this.redisTemplate=redisTemplate;
    }

    @GetMapping("/save")
    public Object save(@RequestParam String key,@RequestParam String value)
    {
        //opsForValue操作String类型
        redisTemplate.opsForValue().set(key,value);
        return "success";
    }
}
